<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
	<style type="text/css">
		#jianju{
			padding-left:60px
		}
		
	</style>
</head>
<body>
<script>
//日期转换
Date.prototype.format = function(format){ 
	var o = { 
	"M+" : this.getMonth()+1, //month 
	"d+" : this.getDate(), //day 
	"h+" : this.getHours(), //hour 
	"m+" : this.getMinutes(), //minute 
	"s+" : this.getSeconds(), //second 
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
	"S" : this.getMilliseconds() //millisecond 
	} 

	if(/(y+)/.test(format)) { 
	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	} 

	for(var k in o) { 
	if(new RegExp("("+ k +")").test(format)) { 
	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
	} 
	} 
	return format; 
	}
//获取病人姓名、年龄
function onchanges(newValue, oldValue){
	$.getJSON("getNAs", {
		"ylkNo" : newValue
	}, function(data) {
		$("#namemxj").textbox("setValue",data.ylkname);
		$("#agemxj").textbox("setValue",data.age);
		$("#ghNomxj").textbox("setValue",data.ghNo);
		
		$.getJSON("getaks",{
			"ghNo":data.ghNo
		},function (data1){
			$("#mxjks").combobox("setValue",data1)
		})
	});
}
//打开科室添加窗口
$(function(){
	$("#adddepartment").linkbutton({
		onClick:function(){
			$("#department").window("open")
		}
	})
	//提交手术单数据
	$("#operationSave").linkbutton({
		onClick:function(){
			if(verif()){
				$('#his_op').form('submit', {
				    url:'do_operation',
				    onSubmit: function(){
				    	
				    },
				    success:function(data){
				    	alert("保存成功！")
				    	var days=new Date();
						var date=days.format("yyyy-MM-dd")
						$("#his_op").form("clear");
						$("#ssTimem").datebox("setValue",date)
						$("#ssType").combobox("setValue",1001)
						$("#ssGrade").combobox("setValue",1001)
						$("#sssNo").combobox("setValue",103)
						$("#ssCost").numberbox("setValue",100.00)
				    }
				});
			}else{
				alert("数据未提交")
			}
		}
	})
	//添加科室
	$("#addNewksMXJ").linkbutton({
		onClick:function(){
			var newks=$("#newksMXJ").textbox("getValue");
			if(!newks){alert("请输入科室名称！")}else{
				$("#apparatus").datagrid("insertRow",{
					index:0,
					row:{
						'ksName':newks
					}
				});
				$("#newksMXJ").textbox("clear");
			}
		}
	});
	//取消添加
	$("#resetks").linkbutton({
		onClick:function(){
			$("#newksMXJ").textbox("clear");
		}
	});
	//删除科室
	$("#deleteksMXJ").linkbutton({
		onClick:function(){
			var row=$("#apparatus").datagrid("getSelections");
			var zz=$("#apparatus").datagrid("getRowIndex",row[0]);
			if(row.length==0){
				alert("未选中行！")
			}else{
				$("#apparatus").datagrid("deleteRow",zz);
			}
		}
	})
	
	//双击修改科室
	$("#apparatus").datagrid({
		onDblClickRow:function(rowIndex, rowData){
			$("#mxjks").combobox("setValue",rowData.ksName)
			alert("科室修改成功！")
			$("#department").window("close")
		}
	})
	//重置表单
	$("#operationReset").linkbutton({
		onClick:function(){
			var days=new Date();
			var date=days.format("yyyy-MM-dd")
			$("#his_op").form("clear");
			$("#ssTimem").datebox("setValue",date)
			$("#ssType").combobox("setValue",1001)
			$("#ssGrade").combobox("setValue",1001)
			$("#sssNo").combobox("setValue",103)
			$("#ssCost").numberbox("setValue",100.00)
		}
	});
	//表单数据验证
	function verif(){
		var ssname=$("#ssName").textbox("getValue");
		var ygno=$("#ygNo").combobox("getValue");
		var sstype=$("#ssType").combobox("getValue");
		var ssgrade=$("#ssGrade").combobox("getValue");
		var sssno=$("#sssNo").combobox("getValue");
		if(!ssname){
			alert("手术名称不能为空！")
			return false;
		}
		if(!ygno){
			alert("未指定手术医生！")
			return false;
		}
		if(!sstype){
			alert("请确定手术类型是否为空！")
			return false;
		}
		if(!ssgrade){
			alert("请确定手术等级是否为空！")
			return false;
		}
		if(!sssno){
			alert("请指定手术室！")
			return false;
		}
		if(ssname && ygno && sstype && ssgrade && sssno ){
			return true;
		}
	}
})
//费用变更
function lxChange(newValue, oldValue){
	$.getJSON('lxcost',{
		'lxNo':newValue
	},function(data){
		$.getJSON('djcost',{
			'djNo':$("#ssGrade").combobox("getValue")
		},function(data2){
			$("#ssCost").numberbox("setValue",data2+data)
		})
	})
}
//费用变更
function djChange(newValue, oldValue){
	$.getJSON('djcost',{
			'djNo':newValue
		},function(data){
			$.getJSON('lxcost',{
				'lxNo':$("#ssType").combobox("getValue")
			},function(data2){
				$("#ssCost").numberbox("setValue",data2+data)
			})
		})
}
</script>  
    <div class="easyui-tabs" data-options="border:false" style="width:100%;height:90%;">
        <div title="手术单" style="padding:10px">
		<form id="his_op">
				<div width="100%"  style="background: rgb(236,243,255); height:50px; padding:10px">
							<select class="easyui-combogrid" name="ylkNo" data-options="label:'卡号',
																							width:'40%', 
																							labelWidth:'20%',
																							panelWidth: '19%',
																							panelHeight: 'auto',
																							url:'getylk',
																							idField: 'ylkNo',
																							textField: 'ylkNo',
																							columns:[[
																				                {field:'brName',title:'姓名',width:95},
																				                {field:'brSex',title:'性别',width:95},
																				                {field:'brAge',title:'年龄',width:95}
																				            ]],
																							onChange:onchanges
																							"></select>
							<span style="margin-left:20px"></span>
							<input id="ghNomxj" class="easyui-textbox" name="ghNo" data-options="width:'40%',label:'门诊号',
																							editable:false, labelWidth:'30%'"/>
							</p>
							<input id="namemxj" class="easyui-textbox" name="brName" data-options="width:'40%',label:'病人姓名',editable:false, labelWidth:'30%'"/>
							<span style="margin-left:20px"></span>
							<input id="agemxj" class="easyui-textbox" name="brAge" data-options="width:'40%',label:'年龄',editable:false, labelWidth:'30%'"/>
				</div>
				<div style="margin-top:10px;height:80%;background: rgb(236,243,255);padding:10px">
					<table id="operationMsg" width="100%" style="height:70%">
						<tr>
							<td><input class="easyui-textbox" name="ssName" id="ssName" data-options="width:'30%',label:'手术名称',labelWidth:'30%'"/>
							<span id="jianju"></span>
							<select class="easyui-combobox" name="ygNo" id="ygNo" data-options="label:'手术医生',
																							labelWidth:'30%',
																							width:'30%', 
																							editable:false, 
																							url:'getdoctor',
																							panelWidth: '10%',
																							panelHeight:'auto',
																							valueField: 'ygNo',
																							textField: 'ygName'"></select></td>
							
						</tr>
						<tr>
							<td><input class="easyui-datebox" id="ssTimem" name="ssTime" value="new date()" data-options="label:'手术时间',width:'30%',labelWidth:'30%'"/>
								<span id="jianju"></span>
								<select id="mxjks" class="easyui-combobox" name="ksName" data-options="label:'科室',
																							width:'30%', 
																							labelWidth:'20%',
																							panelWidth: '11%',
																							url:'AllDepartment',
																							panelHeight:'auto',
																							valueField: 'ksNo',
																							textField: 'ksName'"></select>
								<a id="adddepartment" class="easyui-linkbutton" data-options="iconCls:'icon-add'"></a>
							</td>
						</tr>
						<tr>
							<td>
								<select class="easyui-combobox" name="ssType" id="ssType" data-options="label:'类型',
																							width:'30%',
																							editable:false, 
																							labelWidth:'20%',
																							panelWidth: '11%',
																							url:'AllOperationType',
																							panelHeight:'auto',
																							valueField: 'lxNo',
																							textField: 'lxName',
																							onChange:lxChange
																							">
																							<option value=1001>一类</option>
																							</select>
								<span id="jianju"></span>
								<select class="easyui-combobox" name="ssGrade" id="ssGrade" data-options="label:'等级',
																							editable:false,
																							width:'30%', 
																							labelWidth:'20%',
																							panelWidth: '11%',
																							url:'AlloperationGrade',
																							panelHeight:'auto',
																							valueField: 'djNo',
																							textField: 'djName',
																							onChange:djChange
																							">
																							<option value=1001>一级</option>
																							</select></td>
						</tr>
						<tr>
								<td><select class="easyui-combobox" name="sssNo" id="sssNo" data-options="label:'手术室',
																							width:'30%', 
																							editable:false,
																							labelWidth:'20%',
																							panelWidth: '11%',
																							url:'Alloperationroom',
																							panelHeight:'auto',
																							valueField: 'sssNo',
																							textField: 'sssName'
																							">
																							<option value=103>第一手术室</option>
																							</select>
								<span id="jianju"></span>
								<input class="easyui-numberbox" id="ssCost" name="ssCost" data-options="label:'费用',precision:2,value:100.00,labelWidth:'20%',readonly:true,width:'30%'"/></td>
						</tr>
						<tr>
							<td><input class="easyui-textbox" name="ssRemarks" data-options="label:'备注',width:'40%',labelWidth:'15%',multiline:true,height:'auto'"/></td>
						</tr>
					</table>
					<div style="background: rgb(236,243,255); padding-left:70%">
				<a class="easyui-linkbutton" id="operationSave" data-options="iconCls:'icon-save'"  style="background: rgb(236,243,255)">保存</a>
				<a class="easyui-linkbutton" id="operationReset" data-options="iconCls:'icon-mini-refresh'" style="background: rgb(236,243,255)">重置</a><br>
				</div>
				</div>
			</form>
        </div>
    </div>
<div id="department" class="easyui-window" title="增加科室" data-options="collapsible:false,modal:true,
																							minimizable:false,
																							maximizable:false,
																						closed:true" style="width:20%; height:400px;background: rgb(236,243,255); padding:10px">
	<div  style="width:45%;height:99%;background:#FFF;float:left">
		<table id="apparatus" class="easyui-datagrid"style="height:auto"
							data-options="url:'AllDepartment',
								iconCls: 'icon-edit',
								singleSelect: true
							">
						<thead>
							<tr>
								<th data-options="field:'ksName',width:'110%',editor:'textbox'">科室名称</th>
							</tr>
						</thead>
					</table>
		</div>
		<div  style="width:10%;height:99%;float:left"></div>
		<div style="width:45%;height:96%;background:#FFF;padding-top:10px;float:left">
			<form id="form-department">
				<input class="easyui-textbox" id="newksMXJ" name="kssName" data-options="width:'100%',label:'科室',labelPosition:'top'"/>
				<div style="padding-top:10px">
					<a id="addNewksMXJ" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">新增科室</a>
					<a id="resetks" class="easyui-linkbutton" data-options="iconCls:'icon-mini-refresh'">清除</a>	
					<a id="deleteksMXJ" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">删除科室</a>
				</div>
			</form>
		</div>
</div>
</body>
</html>